package com.mycjj.android.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.mycjj.android.R;
import com.mycjj.android.bean.SettingBaseBean;
import com.mycjj.android.bean.SettingBaseBean.SettingData.EarnBean;
import com.mycjj.android.http.ProjectHttpRequestImpl;
import com.mycjj.android.http.ProjectHttpRequestInterface;
import com.mycjj.android.util.Preferences;
//消费领元宝
public class Score_ConsumeGetGoldActivity extends BaseActivity{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_score_consume_get_gold);
		initHeader();
		init();
		initData();
	}
	
	private ImageView mHeaderLeftImageview;
	private Button mHeaderRightButton;
	private TextView mHeaderTitleTextView;

	private void initHeader() {
		mHeaderLeftImageview = (ImageView) findViewById(R.id.header_left_button);
		mHeaderLeftImageview.setImageResource(R.drawable.back);
		mHeaderRightButton = (Button) findViewById(R.id.header_right_button);
		mHeaderRightButton.setVisibility(View.GONE);
		mHeaderTitleTextView = (TextView) findViewById(R.id.header_title_textview);
		mHeaderTitleTextView.setText("消费领元宝");
		mHeaderLeftImageview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Score_ConsumeGetGoldActivity.this.finish();
			}
		});
	}
	private View mRl_item;
	private TextView tv_item1,tv_item2,tv_item3,tv_item4,tv_item5;
	private void init(){
		mRl_item = findViewById(R.id.rl_item);
		tv_item1 = (TextView)findViewById(R.id.tv_item1);
		tv_item2 = (TextView)findViewById(R.id.tv_item2);
		tv_item3 = (TextView)findViewById(R.id.tv_item3);
		tv_item4 = (TextView)findViewById(R.id.tv_item4);
		tv_item5 = (TextView)findViewById(R.id.tv_item5);
	}
	SettingBaseBean  settingBaseBean;
	private void initData(){
		settingBaseBean = dataManager.getSettingBaseBean();
		if(settingBaseBean == null){
			request = new ProjectHttpRequestImpl(this, true);
			RequestParams params = new RequestParams();
			params.put("client_id", ProjectHttpRequestInterface.client_id_key);
			String token = Preferences.getSharedPreferences(this, "user_token", "");
			params.put("token", token);
			request.requestSyceeGetSettingWithDoneHandler("", params, new AsyncHttpResponseHandler(){
				@Override
				public void onSuccess(String content) {
					settingBaseBean = dataManager.getSettingBaseBean();
					if(settingBaseBean != null){
						if(settingBaseBean.getCode() == 200){
							initView();
						}else{
							Toast.makeText(Score_ConsumeGetGoldActivity.this, settingBaseBean.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}else{
						Log.e("mark", "settingBaseBean is null!!");
					}
				}
			});
		}else{
			initView();
		}
		
	}
	
	private void initView(){
		EarnBean bean  = settingBaseBean.getData().getEarn();
		if(bean != null){
			tv_item1.setText(bean.getBuy_car());//整车购买
			tv_item2.setText(bean.getUpkeep());//汽车包养
			tv_item3.setText(bean.getRepair());//汽车维修
			tv_item4.setText(bean.getFacial());//汽车美容
			tv_item5.setText(bean.getBuy_parts());//购买零配件
		}
	}
	
	
	
}
